﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tiger.Common;
using Appkiz.Library.Security;
using Appkiz.Library.Security.Authentication;

namespace Tiger.Controllers
{
    public class HomeController : Controller
    {

        #region 领导日程查看
        public ActionResult Index()
        {
            try
            {
                // 获得当前用户
                var employee = (User.Identity as AppkizIdentity).Employee;
                bool canSeeLeader = AppPermission.CheckPermission(employee.EmplID, "canSeeLeader");
                bool canScheduleLeader = AppPermission.CheckPermission(employee.EmplID, "canScheduleLeader");
                if (canSeeLeader == true)
                {
                    return View("week");
                }
                else if(canScheduleLeader == true)
                {
                    return View("leader");
                }
                else
                {
                    return Redirect("/Apps/Calendar");
                }
            }
            catch
            {
                return Redirect("/Frame/NeedLogon.aspx?ReturnUrl=/Apps/Calendar");
            }
        }
        #endregion

        #region 个人日历
        public ActionResult PersonalTasks()
        {
            try
            {
                var employee = (User.Identity as AppkizIdentity).Employee;
                return Redirect("/Apps/Calendar");
            }
            catch
            {
                return Redirect("/Frame/NeedLogon.aspx?ReturnUrl=/Apps/Calendar");
            }
        }
        #endregion

        #region 设置领导日程
        /// <summary>
        /// 设置领导日程
        /// </summary>
        /// <returns></returns>
        public ActionResult Leader()
        {
            try
            {
                // 获得当前用户
                var employee = (User.Identity as AppkizIdentity).Employee;
                bool canScheduleLeader = AppPermission.CheckPermission(employee.EmplID, "canScheduleLeader");
                bool isAdmin = AppPermission.CheckPermission(employee.EmplID, "admin");
                if (canScheduleLeader == true || isAdmin == true)
                {
                    return View("leader");
                }
                else
                {
                    return Redirect("/Apps/Calendar");
                }
            }
            catch
            {
                return Redirect("/Frame/NeedLogon.aspx?ReturnUrl=/Apps/Calendar");
            }
        }
        #endregion
    }
}